package com.flyu.mySocket;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpClientDome1 {
    public static void main(String[] args) throws Exception {
        // 1. 建立socket连接
        DatagramSocket socket = new DatagramSocket();

        // 2. 打包
        String msg = "你好啊，服务器";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9999;
        // 数据，数据起始位置和长度，目标地址
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);

        // 3. 发送
        socket.send(packet);

        // 4. 关闭连接
        socket.close();
    }
}
